%% getFilePath
% Prompts the user to select a file of interest and extracts the path
% information from the file
%
%% Syntax
% [ filePath ] = getFilePath(extensionRegex, fileType)
%
% [ filePath ] = getFilePath( '*.oct', 'oct' )
%
%% Description
% This function prompts the user to find a filetype of interest. The files available
% for selection by the user are constratined by the file extension information 
% passed into the function. The function then extracts the path of the file of interest.
%
%% Arguments
%* extensionRegex        - Char: A regular expression specifying the
%                                extension of the filetype of interest
%
%* fileType              - Char: A description of the filetype of interest
%                               (oct, dicom, colormap etc)
%
%% Returns
%* filePath               - Char: The path of the user specified file of interest
%
%% Function Side Effects
%* A window displays prompting the user to select a file of interest
%  matching the provided file extension
%
%% Exceptions
%* An error is thrown if the user fails to select a file of interest
%
%% See Also

function [ filePath, fileName ] = getFilePath(extensionRegex, fileType)

fileSearchValidation(extensionRegex, fileType);

% Prints to the console for the benefit of obnoxious Mac users :D 
fprintf('Please select a %s file of interest', fileType);

% Prompts user to select file of interest
[fileName, pathName] = ...
    uigetfile((extensionRegex), sprintf('Please select a %s file of interest', fileType));

% Verifies user made a selection
if isequal(fileName, 0) == 1 || isequal(pathName, 0) == 1
    
    error('getFilePath:NoFileSelected', ...
        sprintf('User failed to select a %s file', fileType));
    
end

% Verifies that the user selected a file with the specified extension type

[pathstr, name, ext] = fileparts(fileName);

if strcmp(extensionRegex(2:length(extensionRegex)), ext) == 0
    
    error('getFilePath:IncorrectFileTypeSelected', ...
        sprintf('User selected a file with extension %s instead of a %s file', ext, fileType));
    
end 

filePath = strcat(pathName, fileName);

end

